# -*- coding: utf-8 -*-
from utils.operators.cluster_for_spark_sql_hook_test_for_airflow_bug_operator import SparkSqlOperator
from datetime import timedelta

jms_dm__dm_route_whole_node_base_dt_tmp = SparkSqlOperator(
    task_id='jms_dm__dm_route_whole_node_base_dt_tmp',
    pool_slots=2,
    master='yarn',
    execution_timeout = timedelta(hours=2),
    email=['suning@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_route_whole_node_base_dt_tmp_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms_route_test/dm/dm_route_whole_node_base_dt_tmp/execute.hql',
    driver_memory='8G',
    executor_memory='15G',
    executor_cores=6,
    num_executors=60,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled' : 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors' : 80,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.sql.sources.partitionOverwriteMode' : 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead' : '4G',  # 堆外内存
        'spark.sql.shuffle.partitions' : 1200,
        'spark.shuffle.file.buffer' : '64K',
        'spark.shuffle.io.retryWait' : 10,
        'spark.network.timeout': 120,
        'spark.shuffle.memoryFraction': '0.9',
        'spark.storage.memoryFraction': '0.5',
        #'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=6',
        'spark.shuffle.consolidateFiles':'true',
        'spark.executor.extraJavaOptions':'-XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintHeapAtGC -XX:+PrintGCApplicationConcurrentTime -Xloggc:/data1/hadoop/yarn/log/gc.log'
    },
    #hiveconf={
    #    'hive.exec.dynamic.partition' : 'true',  # 动态分区
    #    'hive.exec.dynamic.partition.mode' : 'nonstrict',
    #    'hive.exec.max.dynamic.partitions' : 400,  # 每天生成 20 个分区
    #    'hive.exec.max.dynamic.partitions.pernode': 400,  # 每天生成 20 个分区
    #},
    yarn_queue='route',
)

jms_dm__dm_route_whole_node_base_dt_tmp << [
]
